home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ecltray / traydemo.frm < prev    next >
Text File  |  1998-04-21  |  9KB  |  251 lines

  1. VERSION 5.00
  2. Object = "{E39DB312-D923-11D1-B45E-0020AF33A8E7}#1.0#0"; "ECLTRAY.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Demo using ECLTray Control"
  5.    ClientHeight    =   1356
  6.    ClientLeft      =   48
  7.    ClientTop       =   336
  8.    ClientWidth     =   5100
  9.    LinkTopic       =   "Form1"
  10.    LockControls    =   -1  'True
  11.    MaxButton       =   0   'False
  12.    ScaleHeight     =   1356
  13.    ScaleWidth      =   5100
  14.    ShowInTaskbar   =   0   'False
  15.    StartUpPosition =   2  'CenterScreen
  16.    Begin ECLTrayIcon.Ecltray Ecltray1 
  17.       Left            =   96
  18.       Top             =   1248
  19.       _ExtentX        =   804
  20.       _ExtentY        =   529
  21.       IconToolTip     =   "ECLIPSE« System Tray Icon"
  22.    End
  23.    Begin VB.CommandButton Command4 
  24.       Caption         =   "E&xit"
  25.       Height          =   320
  26.       Left            =   3504
  27.       TabIndex        =   4
  28.       Top             =   850
  29.       Width           =   1500
  30.    End
  31.    Begin VB.CommandButton Command3 
  32.       Caption         =   "&Cycle Icon"
  33.       Height          =   320
  34.       Left            =   1800
  35.       TabIndex        =   3
  36.       Top             =   850
  37.       Width           =   1500
  38.    End
  39.    Begin VB.CommandButton Command2 
  40.       Caption         =   "Hide &Icon"
  41.       Height          =   320
  42.       Left            =   100
  43.       TabIndex        =   2
  44.       Top             =   850
  45.       Width           =   1500
  46.    End
  47.    Begin VB.CommandButton Command1 
  48.       Caption         =   "Change &Tip"
  49.       Height          =   320
  50.       Left            =   144
  51.       TabIndex        =   1
  52.       Top             =   144
  53.       Width           =   1500
  54.    End
  55.    Begin VB.TextBox Text1 
  56.       Height          =   300
  57.       Left            =   1944
  58.       MaxLength       =   64
  59.       TabIndex        =   0
  60.       Text            =   "Text1"
  61.       Top             =   170
  62.       Width           =   2940
  63.    End
  64.    Begin VB.Image Image1 
  65.       Height          =   384
  66.       Index           =   3
  67.       Left            =   2400
  68.       Picture         =   "TrayDemo.frx":0000
  69.       Stretch         =   -1  'True
  70.       ToolTipText     =   "My Computer"
  71.       Top             =   1272
  72.       Visible         =   0   'False
  73.       Width           =   384
  74.    End
  75.    Begin VB.Image Image1 
  76.       Height          =   384
  77.       Index           =   2
  78.       Left            =   1968
  79.       Picture         =   "TrayDemo.frx":08CA
  80.       Stretch         =   -1  'True
  81.       ToolTipText     =   "The Globe"
  82.       Top             =   1272
  83.       Visible         =   0   'False
  84.       Width           =   384
  85.    End
  86.    Begin VB.Image Image1 
  87.       Height          =   384
  88.       Index           =   1
  89.       Left            =   1416
  90.       Picture         =   "TrayDemo.frx":0BD4
  91.       Stretch         =   -1  'True
  92.       ToolTipText     =   "Windows Explorer"
  93.       Top             =   1272
  94.       Visible         =   0   'False
  95.       Width           =   384
  96.    End
  97.    Begin VB.Image Image1 
  98.       Height          =   384
  99.       Index           =   0
  100.       Left            =   888
  101.       Picture         =   "TrayDemo.frx":149E
  102.       Stretch         =   -1  'True
  103.       ToolTipText     =   "Internet Explorer"
  104.       Top             =   1272
  105.       Visible         =   0   'False
  106.       Width           =   384
  107.    End
  108.    Begin VB.Menu mnuMenu 
  109.       Caption         =   "Menu"
  110.       Visible         =   0   'False
  111.       Begin VB.Menu mnuRestore 
  112.          Caption         =   "&Restore"
  113.       End
  114.       Begin VB.Menu mnuMinimize 
  115.          Caption         =   "Mi&nimize"
  116.       End
  117.       Begin VB.Menu mnuExit 
  118.          Caption         =   "E&xit"
  119.       End
  120.    End
  121. End
  122. Attribute VB_Name = "Form1"
  123. Attribute VB_GlobalNameSpace = False
  124. Attribute VB_Creatable = False
  125. Attribute VB_PredeclaredId = True
  126. Attribute VB_Exposed = False
  127. Option Explicit
  128. ' This declares should be in a module but I want to keep the code in a single file
  129. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  130. Private Declare Sub PostQuitMessage Lib "user32" (ByVal nExitCode As Long)
  131.  
  132. Dim OldIcon As StdPicture
  133. Dim OldToolTip As String
  134. Dim IconId As Integer
  135.  
  136. Private Sub Command1_Click()
  137.      Ecltray1.IconToolTip = Text1.Text
  138. End Sub
  139.  
  140. Private Sub Command2_Click()
  141.     With Ecltray1
  142.         If .ShowIcon Then
  143.             Command2.Caption = "Show &Icon"
  144.             .ShowIcon = False
  145.         Else
  146.             Command2.Caption = "Hide &Icon"
  147.             .ShowIcon = True
  148.         End If
  149.     End With
  150.      
  151. End Sub
  152.  
  153. Private Sub Command3_Click()
  154.     If IconId > 4 Then IconId = 0                       'maximum number of Icon that we have
  155.     Select Case IconId
  156.     Case 0:
  157.             Set Ecltray1.TrayIcon = OldIcon         'Control's Stored Icon
  158.             Ecltray1.IconToolTip = OldToolTip       'control's stored ToolTip
  159.             Text1.Text = OldToolTip
  160.     Case 1 To 4:
  161.             Set Ecltray1.TrayIcon = Image1(IconId - 1).Picture ' copy the Image stored in Image1 -must be an Icon!
  162.             Ecltray1.IconToolTip = Image1(IconId - 1).ToolTipText   ' copy the ToolTipText of Image1. This can be set to anything
  163.             Text1.Text = Image1(IconId - 1).ToolTipText
  164.     End Select
  165.     
  166.     IconId = IconId + 1
  167.     
  168. End Sub
  169.  
  170. Private Sub Command4_Click()
  171.     mnuExit_Click
  172.     
  173. End Sub
  174.  
  175. Private Sub Ecltray1_DblClick(Button As Integer)
  176.     If WindowState = 0 Then             'I tried to use 'If Not WindowState' but the Else part wouldn't trigger. I don't know why.
  177.         WindowState = vbMinimized       ' minimize the form
  178.     Else
  179.         WindowState = vbNormal          ' limit the viewable state to normal
  180.         SetForegroundWindow (Me.hwnd)   'Ensure the form is visible and has the  focus
  181.     End If
  182. End Sub
  183.  
  184. Private Sub ecltray1_MouseUp(Button As Integer, shift As Integer, X As Single, Y As Single)
  185. ' Button can be 1(Left); 2(Right) or 4(Middle)
  186. ' Shift can be 1(Shiftkey is down), 2(ControlKey is down) and 4 (AltKey is Down)
  187. ' Note that value of shift can be one or combination of the three keys.i.e. 6=(Ctrl and Alt keys as pressed)
  188. ' The value of X and Y indicates the location of the mouse cursor
  189.      
  190.     If Button = 2 Then                              ' Execute only when the right Mouse Button is pressed and release
  191.         SetForegroundWindow (Me.hwnd)               'Activate form1
  192.         PopupMenu mnuMenu, vbPopupMenuRightAlign    'pops up the menu we created 'mnuMenu'
  193.     End If
  194.      
  195. End Sub
  196.  
  197. Private Sub Form_Load()
  198.     Set OldIcon = Ecltray1.TrayIcon                 'copy the control's stored Icon & ToolTipText
  199.     OldToolTip = Ecltray1.IconToolTip
  200.     Text1.Text = OldToolTip
  201.     IconId = 1                                      'set the next icon to be displayed when the Cycle Icon button is pressed
  202.      
  203. End Sub
  204.  
  205. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  206.     Set Form1 = Nothing
  207.     
  208. End Sub
  209.  
  210. Private Sub Form_Resize()
  211.     If WindowState Then
  212.         mnuMinimize.Enabled = False
  213.         mnuRestore.Enabled = True
  214.     Else
  215.         mnuMinimize.Enabled = True
  216.         mnuRestore.Enabled = False
  217.     End If
  218.      
  219. End Sub
  220.  
  221. Private Sub mnuExit_Click()
  222. ' ***************************************************************
  223. ' NOTE: Quiting the program from the system Icon (popupmenu) by
  224. '       means of 'Unload Form1' statement will generate an 'Invalid
  225. '       Page Fault in Module <unknown>' message. This will happen
  226. '       only when you try to exit the program using the System Icon.
  227. '       I still don't know why this happen. To work around this
  228. '       problem I used an API call to quit the program properly
  229. '       'Postquitmessage (nExitCode as Long)'. There is one  problem
  230. '       with it, however. if you remove the code 'X = MsgBox...', the
  231. '       Exit code will be ignored and the program will continue running.
  232. '       So, the MsgBox is necessary to shut the program. Again, I still
  233. '       don't know why this happen. Please send me some information if
  234. '       you know how to work around these problems, because I'm still
  235. '